import astropy.io.fits as fits
import math
import numpy as np
import pickle

flux_dict=pickle.load(open("flux_dict.pickle", "rb"))
hdo_225=fits.open('V883_Ori_SB_HDO-225.535GHz_robust_2.0.image.fits')
hdo_225_mask=fits.open('V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-hdo.fits')
hdo_225_ch3ocho_mask=fits.open('V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-ch3ocho.fits')
hdo_225_rms=1.13e-3
hdo_225_header=hdo_225[0].header
hdo_225_nchans=hdo_225_header['NAXIS3']
hdo_225_dv=hdo_225_header['CDELT3']/hdo_225_header['CRVAL3']*3.0e5*-1.0
hdo_225_dv=0.4
hdo_225_velocity=np.zeros(hdo_225_nchans)
hdo_225_sum=np.zeros(hdo_225_nchans)
e_hdo_225_sum=np.zeros(hdo_225_nchans)
hdo_225_sum_241_missing_range=np.zeros(hdo_225_nchans)
e_hdo_225_sum_241_missing_range=np.zeros(hdo_225_nchans)
hdo_225_sum_203_missing_range=np.zeros(hdo_225_nchans)
e_hdo_225_sum_203_missing_range=np.zeros(hdo_225_nchans)
hdo_225_sum_203_241_missing_range=np.zeros(hdo_225_nchans)
e_hdo_225_sum_203_241_missing_range=np.zeros(hdo_225_nchans)
hdo_225_sum_241_contamination=np.zeros(hdo_225_nchans)
e_hdo_225_sum_241_contamination=np.zeros(hdo_225_nchans)
hdo_225_ch3ocho_sum=np.zeros(hdo_225_nchans)
e_hdo_225_ch3ocho_sum=np.zeros(hdo_225_nchans)
npix_hdo_225_beam=3.14159*hdo_225_header['BMAJ']*hdo_225_header['BMIN']/(4.0*math.log(2.0))/hdo_225_header['CDELT2']**2


for i in range(hdo_225_nchans):
   hdo_225_velocity[i]=hdo_225_header['ALTRVAL']/1000.0+hdo_225_dv*i

for i in range(hdo_225_nchans):
   indices=(np.squeeze(hdo_225_mask[0].data)[i]==1).nonzero()
   npix_hdo=len(indices[0])
   indices_ch3ocho=(np.squeeze(hdo_225_ch3ocho_mask[0].data)[i]==1).nonzero()
   npix_ch3ocho=len(indices_ch3ocho[0])
   if (hdo_225_velocity[i] < 9.25) and (hdo_225_velocity[i] > -1.0):
      hdo_225_sum[i]=np.sum(hdo_225[0].data[i,indices[0],indices[1]])/npix_hdo_225_beam
      e_hdo_225_sum[i]=(npix_hdo/npix_hdo_225_beam)**0.5*hdo_225_rms
   if (hdo_225_velocity[i] < 1.0) and (hdo_225_velocity[i] > -1.0):
      hdo_225_sum_241_missing_range[i]=np.sum(hdo_225[0].data[i,indices[0],indices[1]])/npix_hdo_225_beam
      e_hdo_225_sum_241_missing_range[i]=(npix_hdo/npix_hdo_225_beam)**0.5*hdo_225_rms
   if (hdo_225_velocity[i] < 2.0) and (hdo_225_velocity[i] > -1.0):
      hdo_225_sum_203_missing_range[i]=np.sum(hdo_225[0].data[i,indices[0],indices[1]])/npix_hdo_225_beam
      e_hdo_225_sum_203_missing_range[i]=(npix_hdo/npix_hdo_225_beam)**0.5*hdo_225_rms
   if (hdo_225_velocity[i] < 7.1) and (hdo_225_velocity[i] > 5.0):
      hdo_225_sum_203_241_missing_range[i]=np.sum(hdo_225[0].data[i,indices[0],indices[1]])/npix_hdo_225_beam
      e_hdo_225_sum_203_241_missing_range[i]=(npix_hdo/npix_hdo_225_beam)**0.5*hdo_225_rms
   if (hdo_225_velocity[i] < 9.334) and (hdo_225_velocity[i] > 7.334):
      hdo_225_sum_241_contamination[i]=np.sum(hdo_225[0].data[i,indices[0],indices[1]])/npix_hdo_225_beam
      e_hdo_225_sum_241_contamination[i]=(npix_hdo/npix_hdo_225_beam)**0.5*hdo_225_rms
   if (hdo_225_velocity[i] < 2.5) and (hdo_225_velocity[i] > -4.8):
      hdo_225_ch3ocho_sum[i]=np.sum(hdo_225[0].data[i,indices_ch3ocho[0],indices_ch3ocho[1]])/npix_hdo_225_beam
      e_hdo_225_ch3ocho_sum[i]=(npix_ch3ocho/npix_hdo_225_beam)**0.5*hdo_225_rms
   #print('{:0.2f} {:0.4f} {:0.4f} {:0.0f} {:0.4f} {:0.4f} {:0.0f} '.format(hdo_225_velocity[i],hdo_225_sum[i],e_hdo_225_sum[i],npix_hdo,hdo_225_ch3ocho_sum[i],e_hdo_225_ch3ocho_sum[i],npix_ch3ocho))

hdo_225_total_flux=0.0
e_hdo_225_total_flux=0.0
hdo_225_total_flux_241_missing_range=0.0
e_hdo_225_total_flux_241_missing_range=0.0
hdo_225_total_flux_203_missing_range=0.0
e_hdo_225_total_flux_203_missing_range=0.0
hdo_225_total_flux_203_241_missing_range=0.0
e_hdo_225_total_flux_203_241_missing_range=0.0
hdo_225_total_flux_241_contamination=0.0
e_hdo_225_total_flux_241_contamination=0.0
hdo_225_ch3ocho_total_flux=0.0
e_hdo_225_ch3ocho_total_flux=0.0

for i in range(hdo_225_nchans):
   if hdo_225_sum[i] >0.0:
      hdo_225_total_flux+=hdo_225_sum[i]
      e_hdo_225_total_flux+=e_hdo_225_sum[i]**2
   if hdo_225_sum_241_missing_range[i] >0.0:
      hdo_225_total_flux_241_missing_range+=hdo_225_sum_241_missing_range[i]
      e_hdo_225_total_flux_241_missing_range+=e_hdo_225_sum_241_missing_range[i]**2
   if hdo_225_sum_203_missing_range[i] >0.0:
      hdo_225_total_flux_203_missing_range+=hdo_225_sum_203_missing_range[i]
      e_hdo_225_total_flux_203_missing_range+=e_hdo_225_sum_203_missing_range[i]**2
   if hdo_225_sum_203_241_missing_range[i] >0.0:
      hdo_225_total_flux_203_241_missing_range+=hdo_225_sum_203_241_missing_range[i]
      e_hdo_225_total_flux_203_241_missing_range+=e_hdo_225_sum_203_241_missing_range[i]**2
   if hdo_225_sum_241_contamination[i] >0.0:
      hdo_225_total_flux_241_contamination+=hdo_225_sum_241_contamination[i]
      e_hdo_225_total_flux_241_contamination=e_hdo_225_sum_241_contamination[i]**2

   if hdo_225_ch3ocho_sum[i] >0.0:
      hdo_225_ch3ocho_total_flux+=hdo_225_ch3ocho_sum[i]
      e_hdo_225_ch3ocho_total_flux+=e_hdo_225_ch3ocho_sum[i]**2

e_hdo_225_ch3ocho_total_flux=e_hdo_225_ch3ocho_total_flux**0.5
e_hdo_225_total_flux=e_hdo_225_total_flux**0.5
e_hdo_225_total_flux_241_missing_range=e_hdo_225_total_flux_241_missing_range**0.5
e_hdo_225_total_flux_203_missing_range=e_hdo_225_total_flux_203_missing_range**0.5
e_hdo_225_total_flux_203_241_missing_range=e_hdo_225_total_flux_203_241_missing_range**0.5

print('Total HDO 225 GHz flux: {:0.4f} {:0.4f}, CH3OCHO flux: {:0.4f} {:0.4f} '.format(hdo_225_total_flux,e_hdo_225_total_flux,hdo_225_ch3ocho_total_flux,e_hdo_225_ch3ocho_total_flux))   
print('Total HDO 225 GHz flux: {:0.4f} {:0.4f} 0.1 to 1.0 km/s '.format(hdo_225_total_flux_241_missing_range,e_hdo_225_total_flux_241_missing_range))   
print('Total HDO 225 GHz flux: {:0.4f} {:0.4f} 0.1 to 2.0 km/s '.format(hdo_225_total_flux_203_missing_range,e_hdo_225_total_flux_203_missing_range))   
print('Total HDO 225 GHz flux: {:0.4f} {:0.4f} 5.05 to 7.05 km/s '.format(hdo_225_total_flux_203_241_missing_range,e_hdo_225_total_flux_203_241_missing_range))   
print('Total HDO 225 GHz flux: {:0.4f} {:0.4f} 7.33 to 9.33 km/s '.format(hdo_225_total_flux_241_contamination,e_hdo_225_total_flux_241_contamination))   
flux_frac_5_to_7=hdo_225_total_flux_203_241_missing_range/hdo_225_total_flux
e_flux_frac_5_to_7=flux_frac_5_to_7*((e_hdo_225_total_flux_203_241_missing_range/hdo_225_total_flux_203_241_missing_range)**2+(e_hdo_225_total_flux/hdo_225_total_flux)**2)**0.5
print('Ratio of 5 to 7 km/s Flux to Total HDO 225 GHz flux : {:0.4f} {:0.4f} 5.05 to 7.05 km/s '.format(flux_frac_5_to_7,e_flux_frac_5_to_7))   

flux_frac_7_to_9=hdo_225_total_flux_241_contamination/hdo_225_total_flux
e_flux_frac_7_to_9=flux_frac_7_to_9*((e_hdo_225_total_flux_241_contamination/hdo_225_total_flux_241_contamination)**2+(e_hdo_225_total_flux/hdo_225_total_flux)**2)**0.5
print('Ratio of 7 to 9 km/s Flux to Total HDO 225 GHz flux : {:0.4f} {:0.4f} 7.33 to 9.33 km/s '.format(flux_frac_7_to_9,e_flux_frac_7_to_9))   

key='HDO_225'
flux_dict[key]['flux_kepmask_raw'],flux_dict[key]['e_flux_kepmask_raw']=hdo_225_total_flux,e_hdo_225_total_flux
flux_dict[key]['flux_kepmask_5_to_7'],flux_dict[key]['e_flux_kepmask_5_to_7']=hdo_225_total_flux_203_241_missing_range,e_hdo_225_total_flux_203_241_missing_range
flux_dict[key]['flux_frac_5_to_7'],flux_dict[key]['e_flux_frac_5_to_7']=flux_frac_5_to_7,e_flux_frac_5_to_7
flux_dict[key]['flux_frac_7_to_9'],flux_dict[key]['e_flux_frac_7_to_9']=flux_frac_7_to_9,e_flux_frac_7_to_9


hdo_241=fits.open('V883_Ori_SB_HDO-241.558GHz_robust_2.0.image.fits')
hdo_241_mask=fits.open('V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-hdo.fits')
hdo_241_ch3cho_mask=fits.open('V883_Ori_SB_HDO-241.558GHz_robust_2.0.mask-ch3cho.fits')

hdo_241_rms=1.3e-3
hdo_241_header=hdo_241[0].header
hdo_241_nchans=hdo_241_header['NAXIS3']
hdo_241_dv=hdo_241_header['CDELT3']/hdo_241_header['CRVAL3']*3.0e5*-1.0
hdo_241_dv=0.4
hdo_241_velocity=np.zeros(hdo_241_nchans)
hdo_241_sum=np.zeros(hdo_241_nchans)
e_hdo_241_sum=np.zeros(hdo_241_nchans)
hdo_241_5_to_7_sum=np.zeros(hdo_241_nchans)
e_hdo_241_5_to_7_sum=np.zeros(hdo_241_nchans)

hdo_241_ch3cho_sum=np.zeros(hdo_241_nchans)
e_hdo_241_ch3cho_sum=np.zeros(hdo_241_nchans)
npix_hdo_241_beam=3.14159*hdo_241_header['BMAJ']*hdo_241_header['BMIN']/(4.0*math.log(2.0))/hdo_241_header['CDELT2']**2

for i in range(hdo_241_nchans):
   hdo_241_velocity[i]=hdo_241_header['ALTRVAL']/1000.0+hdo_241_dv*i


for i in range(hdo_241_nchans):
   indices=(np.squeeze(hdo_241_mask[0].data)[i]==1).nonzero()
   npix_hdo=len(indices[0])
   indices_ch3ocho=(np.squeeze(hdo_241_ch3cho_mask[0].data)[i]==1).nonzero()
   npix_ch3ocho=len(indices_ch3ocho[0])
   if (hdo_241_velocity[i] < 8.2) and (hdo_241_velocity[i] > 1.0):
      hdo_241_sum[i]=np.sum(hdo_241[0].data[i,indices[0],indices[1]])/npix_hdo_241_beam
      e_hdo_241_sum[i]=(npix_hdo/npix_hdo_241_beam)**0.5*hdo_241_rms
   if (hdo_241_velocity[i] < 7.1) and (hdo_241_velocity[i] > 5.0):
      hdo_241_5_to_7_sum[i]=np.sum(hdo_241[0].data[i,indices[0],indices[1]])/npix_hdo_241_beam
      e_hdo_241_5_to_7_sum[i]=(npix_hdo/npix_hdo_241_beam)**0.5*hdo_241_rms
   if (hdo_241_velocity[i] < 5.0) and (hdo_241_velocity[i] > -4.8):
      hdo_241_ch3cho_sum[i]=np.sum(hdo_241[0].data[i,indices_ch3ocho[0],indices_ch3ocho[1]])/npix_hdo_241_beam
      e_hdo_241_ch3cho_sum[i]=(npix_ch3ocho/npix_hdo_241_beam)**0.5*hdo_241_rms
   #print('{:0.2f} {:0.4f} {:0.4f} {:0.0f} {:0.4f} {:0.4f} {:0.0f} '.format(hdo_241_velocity[i],hdo_241_sum[i],e_hdo_241_sum[i],npix_hdo,hdo_241_ch3cho_sum[i],e_hdo_241_ch3cho_sum[i],npix_ch3ocho))

hdo_241_total_flux=0.0
e_hdo_241_total_flux=0.0
hdo_241_5_to_7_total_flux=0.0
e_hdo_241_5_to_7_total_flux=0.0
hdo_241_ch3cho_total_flux=0.0
e_hdo_241_ch3cho_total_flux=0.0

for i in range(hdo_241_nchans):
   if hdo_241_sum[i] >0.0:
      hdo_241_total_flux+=hdo_241_sum[i]
      e_hdo_241_total_flux+=e_hdo_241_sum[i]**2
   if hdo_241_5_to_7_sum[i] >0.0:
      hdo_241_5_to_7_total_flux+=hdo_241_5_to_7_sum[i]
      e_hdo_241_5_to_7_total_flux+=e_hdo_241_5_to_7_sum[i]**2

   if hdo_241_ch3cho_sum[i] >0.0:
      hdo_241_ch3cho_total_flux+=hdo_241_ch3cho_sum[i]
      e_hdo_241_ch3cho_total_flux+=e_hdo_241_ch3cho_sum[i]**2

e_hdo_241_ch3cho_total_flux=e_hdo_241_ch3cho_total_flux**0.5
e_hdo_241_total_flux=e_hdo_241_total_flux**0.5
e_hdo_241_5_to_7_total_flux=e_hdo_241_5_to_7_total_flux**0.5
print('Total HDO 241 GHz flux: {:0.4f} {:0.4f}, CH3CHO flux: {:0.4f} {:0.4f} '.format(hdo_241_total_flux,e_hdo_241_total_flux,hdo_241_ch3cho_total_flux,e_hdo_241_ch3cho_total_flux))
#correct for amount of contamination; CH3CHO line flux is ~0.8 Jy from spectral fitting
hdo_241_5_to_7_total_flux=hdo_241_5_to_7_total_flux-0.8*flux_frac_7_to_9
print('HDO 241 GHz 5 to 7 km/s GHz flux: {:0.4f} {:0.4f} '.format(hdo_241_5_to_7_total_flux,e_hdo_241_5_to_7_total_flux))
hdo_241_scaled_total_flux=hdo_241_5_to_7_total_flux/flux_frac_5_to_7
e_hdo_241_scaled_total_flux=hdo_241_scaled_total_flux*((e_hdo_241_5_to_7_total_flux/hdo_241_5_to_7_total_flux)**2+(e_flux_frac_5_to_7/flux_frac_5_to_7)**2)**0.5
print('HDO 241 GHz Total (scaled from 5 to 7 km/s)  flux: {:0.4f} {:0.4f} '.format(hdo_241_scaled_total_flux,e_hdo_241_scaled_total_flux))
hdo_241_scaled_total_flux_minus=(hdo_241_5_to_7_total_flux)/flux_frac_5_to_7
e_hdo_241_scaled_total_flux_minus=hdo_241_scaled_total_flux*((e_hdo_241_5_to_7_total_flux/hdo_241_5_to_7_total_flux)**2+(e_flux_frac_5_to_7/flux_frac_5_to_7)**2)**0.5
print('HDO 241 GHz Total (scaled from 5 to 7 km/s; minus CH3CHO est) flux: {:0.4f} {:0.4f} '.format(hdo_241_scaled_total_flux_minus,e_hdo_241_scaled_total_flux_minus))

key='HDO_241'
flux_dict[key]['flux_kepmask_raw'],flux_dict[key]['e_flux_kepmask_raw']=hdo_241_total_flux,e_hdo_241_total_flux
flux_dict[key]['flux_kepmask_5_to_7'],flux_dict[key]['e_flux_kepmask_5_to_7']=hdo_241_5_to_7_total_flux,e_hdo_241_5_to_7_total_flux
flux_dict[key]['flux_kepmask_scale_5_to_7'],flux_dict[key]['e_flux_kepmask_scale_5_to_7']=hdo_241_scaled_total_flux,e_hdo_241_scaled_total_flux
flux_dict[key]['flux_kepmask_scale_5_to_7_minus'],flux_dict[key]['e_flux_kepmask_scale_5_to_7_minus']=hdo_241_scaled_total_flux_minus,e_hdo_241_scaled_total_flux_minus





h218o_203=fits.open('V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.image.fits')
h218o_203_mask=fits.open('V883_Ori_SB_H218O-203.GHz-0.4kms_robust_2.0.mask-h218o.fits')
#h218o_203_ch3ocho_mask=fits.open('V883_Ori_SB_HDO-225.535GHz_robust_2.0.mask-ch3ocho.fits')
h218o_203_rms=1.58e-3
h218o_203_header=h218o_203[0].header
h218o_203_nchans=h218o_203_header['NAXIS3']
h218o_203_dv=h218o_203_header['CDELT3']/h218o_203_header['CRVAL3']*3.0e5*-1.0
h218o_203_dv=0.4
h218o_203_velocity=np.zeros(h218o_203_nchans)
h218o_203_sum=np.zeros(h218o_203_nchans)
e_h218o_203_sum=np.zeros(h218o_203_nchans)
h218o_203_5_to_7_sum=np.zeros(h218o_203_nchans)
e_h218o_203_5_to_7_sum=np.zeros(h218o_203_nchans)
#h218o_203_ch3ocho_sum=np.zeros(h218o_203_nchans)
#e_h218o_203_ch3ocho_sum=np.zeros(h218o_203_nchans)
npix_h218o_203_beam=3.14159*h218o_203_header['BMAJ']*h218o_203_header['BMIN']/(4.0*math.log(2.0))/h218o_203_header['CDELT2']**2


for i in range(h218o_203_nchans):
   h218o_203_velocity[i]=h218o_203_header['ALTRVAL']/1000.0+h218o_203_dv*i

for i in range(h218o_203_nchans):
   indices=(h218o_203_mask[0].data[i]==1).nonzero()
   npix_hdo=len(indices[0])
   #indices_ch3ocho=(h218o_203_ch3ocho_mask[0].data[0,i]==1).nonzero()
   #npix_ch3ocho=len(indices_ch3ocho[0])
   if (h218o_203_velocity[i] < 8.2) and (h218o_203_velocity[i] > 2.0):
      h218o_203_sum[i]=np.sum(h218o_203[0].data[i,indices[0],indices[1]])/npix_h218o_203_beam
      e_h218o_203_sum[i]=(npix_hdo/npix_h218o_203_beam)**0.5*h218o_203_rms

   if (h218o_203_velocity[i] < 7.1) and (h218o_203_velocity[i] > 5.0):
      h218o_203_5_to_7_sum[i]=np.sum(h218o_203[0].data[i,indices[0],indices[1]])/npix_h218o_203_beam
      e_h218o_203_5_to_7_sum[i]=(npix_hdo/npix_h218o_203_beam)**0.5*h218o_203_rms
   '''
   if (h218o_203_velocity[i] < 2.5) and (h218o_203_velocity[i] > -4.8):
      h218o_203_ch3ocho_sum[i]=np.sum(h218o_203[0].data[i,indices_ch3ocho[0],indices_ch3ocho[1]])/npix_h218o_203_beam
      e_h218o_203_ch3ocho_sum[i]=(npix_ch3ocho/npix_h218o_203_beam)**0.5*h218o_203_rms
   #print('{:0.2f} {:0.4f} {:0.4f} {:0.0f} {:0.4f} {:0.4f} {:0.0f} '.format(h218o_203_velocity[i],h218o_203_sum[i],e_h218o_203_sum[i],npix_hdo,h218o_203_ch3ocho_sum[i],e_h218o_203_ch3ocho_sum[i],npix_ch3ocho))
   '''
h218o_203_total_flux=0.0
e_h218o_203_total_flux=0.0
h218o_203_5_to_7_total_flux=0.0
e_h218o_203_5_to_7_total_flux=0.0
h218o_203_ch3ocho_total_flux=0.0
e_h218o_203_ch3ocho_total_flux=0.0

for i in range(h218o_203_nchans):
   if h218o_203_sum[i] >0.0:
      h218o_203_total_flux+=h218o_203_sum[i]
      e_h218o_203_total_flux+=e_h218o_203_sum[i]**2

   if h218o_203_5_to_7_sum[i] >0.0:
      h218o_203_5_to_7_total_flux+=h218o_203_5_to_7_sum[i]
      e_h218o_203_5_to_7_total_flux+=e_h218o_203_5_to_7_sum[i]**2


   '''
   if h218o_203_ch3ocho_sum[i] >0.0:
      h218o_203_ch3ocho_total_flux+=h218o_203_ch3ocho_sum[i]
      e_h218o_203_ch3ocho_total_flux+=e_h218o_203_ch3ocho_sum[i]**2
   '''
#e_h218o_203_ch3ocho_total_flux=e_h218o_203_ch3ocho_total_flux**0.5
e_h218o_203_total_flux=e_h218o_203_total_flux**0.5
e_h218o_203_5_to_7_total_flux=e_h218o_203_5_to_7_total_flux**0.5

#print('Total H218O 203 GHz flux: {:0.4f} {:0.4f}, CH3OCHO flux: {:0.4f} {:0.4f} '.format(h218o_203_total_flux,e_h218o_203_total_flux,h218o_203_ch3ocho_total_flux,e_h218o_203_ch3ocho_total_flux))   
print('Total H218O 203 GHz flux: {:0.4f} {:0.4f} '.format(h218o_203_total_flux,e_h218o_203_total_flux))   
print('H218O 5 to 7 km/s 203 GHz flux: {:0.4f} {:0.4f} '.format(h218o_203_5_to_7_total_flux,e_h218o_203_5_to_7_total_flux))
h218o_203_scaled_total_flux=h218o_203_5_to_7_total_flux/flux_frac_5_to_7
e_h218o_203_scaled_total_flux=h218o_203_scaled_total_flux*((e_h218o_203_5_to_7_total_flux/h218o_203_5_to_7_total_flux)**2+(e_flux_frac_5_to_7/flux_frac_5_to_7)**2)**0.5
print('H218O Total (scaled from 5 to 7 km/s) 203 GHz flux: {:0.4f} {:0.4f} '.format(h218o_203_scaled_total_flux,e_h218o_203_scaled_total_flux))
8


key='H218O_203'
flux_dict[key]['flux_kepmask_raw'],flux_dict[key]['e_flux_kepmask_raw']=h218o_203_total_flux,e_h218o_203_total_flux
flux_dict[key]['flux_kepmask_5_to_7'],flux_dict[key]['e_flux_kepmask_5_to_7']=h218o_203_5_to_7_total_flux,e_h218o_203_5_to_7_total_flux
flux_dict[key]['flux_kepmask_scale_5_to_7'],flux_dict[key]['e_flux_kepmask_scale_5_to_7']=h218o_203_scaled_total_flux,e_h218o_203_scaled_total_flux


pickle.dump(flux_dict, open("flux_dict.pickle", "wb"))

